$(function () {
    var t = sessionStorage.getItem("uid");
    t || (location.hash = "login", console.error("uid not exist"));
    var a = sessionStorage.getItem("user");
    $("#user").text(a),
        $.get(hostUrl + "/customer/info",
            function (t) {
                !0 === t.meta.success ? ($("#bankId").val(t.data.id), $("#card-no").text(t.data.bank_card_code), $("#bank-name").val(t.data.bank_name), $("#bank-branch").val(t.data.bank_branch), $("#bank-province").val(t.data.bank_province), $("#bank-city").val(t.data.bank_city)) : $.toptip(t.meta.message, "error")
            }),
        $("#returnLink").on("click",
            function () {
                vipspa.setMessage({
                    id: "person_info",
                    content: {
                        tab: "uInfo"
                    }
                }),
                    location.hash = "trade"
            }),
        $("#edit-bank").on("click",
            function () {
                location.hash = "edit-bank"
            });
    var n = 60,
        e = function () {
            var t = $("#vcodeBtn");
            if (0 === n) return t.attr("disabled", !1),
                t.text("获取验证码"),
                n = 60,
                !1;
            t.attr("disabled", !0),
                t.text("(" + n + ")秒"),
                n-- ,
                setTimeout(function () {
                    e()
                },
                    1e3)
        };
    $("#vcodeBtn").on("click",
        function () {
            initNECaptcha({
                captchaId: '01531427d5c245a99f1571dc30df0d01',
                element: '#captcha',
                mode: 'popup',
                width: 320,
                onReady: function (instance) {

                    // 验证码一切准备就绪，此时可正常使用验证码的相关功能
                },
                onVerify: function (err, data) {
                    if (!err) {
                        $.ajax({
                            method: "POST",
                            url: hostUrl + "/sms/get_sms_code",
                            data: JSON.stringify({
                                sms_code_type: 2,
                                captchaId: '01531427d5c245a99f1571dc30df0d01',
                                validate: data.validate
                            }),
                            contentType: "application/json; charset=utf-8",
                            success: function (t) {
                                if (!0 !== t.meta.success) {
                                    $.toptip(t.meta.message, "error");
                                } else {
                                    $.toptip("验证码已发送到您的手机上，请查收！", "success");
                                    e()
                                }
                            }
                        })

                    }
                }
            }, function onload(instance) {
                instance.popUp();
                // 初始化成功
            }, function onerror(err) {
                // 验证码初始化失败处理逻辑，例如：提示用户点击按钮重新初始化
            });

        }),
        $("#update-bank-btn").on("click",
            function () {
                var a = $("#card-no").text(),
                    n = $("#bank-name").val(),
                    e = $("#bank-branch").val(),
                    o = $("#bank-province").val(),
                    c = $("#bank-city").val(),
                    i = $("#bankId").val(),
                    s = $("#vcode").val();
                s ? a ? n ? e ? o ? c ? $.ajax({
                    method: "post",
                    url: hostUrl + "/customer/update-pay-info",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify({
                        "uid": t,
                        "id": i,
                        "vcode": s,
                        "bank_card_code": a,
                        "bank_name": n,
                        "bank_branch": e,
                        "bank_province": o,
                        "bank_city": c
                    }),
                    success: function (t) {
                        !0 !== t.meta.success ? $.toptip(t.meta.message, "error") : ($.toptip("操作成功", "success"), setTimeout(function () {
                            location.hash = "bank-info"
                        },
                            800))
                    }
                }) : $.toptip("请输入开户行所在城市") : $.toptip("请输入开户行所在省") : $.toptip("请输入支行名称") : $.toptip("请输入开户行名称") : $.toptip("请输入银行卡号") : $.toptip("请输入验证码")
            })
});